/*
 * One example for NOI CSP-J Lesson 10:
 * <https://courses.fmsoft.cn/plzs/noijunior-csp-exercises-lower.html>
 *
 * Author: Vincent Wei
 *  - <https://github.com/VincentWei>
 *  - <https://gitee.com/vincentwei7>
 *
 * Copyright (C) 2025 FMSoft <https://www.fmsoft.cn>.
 * License: GPLv3
 */
#include <iostream>
#include <vector>
#include <cassert>

using namespace std;

using llong_t = long long;

vector<llong_t> prime_factors(llong_t n)
{
    vector<llong_t> factors;

    for (llong_t i = 2; i <= n; i++) {
        if (n % i == 0) {
            do {
                n = n / i;
            } while (n % i == 0);

            factors.push_back(i);
        }
    }

    return factors;
}

llong_t gcd(llong_t a, llong_t b)
{
    while (b != 0) {
        llong_t tmp = a;
        a = b;
        b = tmp % b;
    }

    return a;
}

string raitional_number(llong_t a, llong_t b)
{
    llong_t c = gcd(a, b);
    a /= c;
    b /= c;

    char buf[64];

    if (b == 1)
        snprintf(buf, sizeof(buf), "%lld", a);
    else {
        if (b < 0) {
            a = -a;
            b = -b;
        }

        snprintf(buf, sizeof(buf), "%lld/%lld", a, b);
    }

    return buf;
}

string resolve_uqe(llong_t a, llong_t b, llong_t c)
{
    llong_t delta = b * b - 4 * a * c;

    llong_t sqrt;
    if (delta < 0) {
        return "NO";
    }
    else if (delta == 0) {
        sqrt = 0;
    }
    else if (delta == 1) {
        sqrt = 1;
    }
    else {
        sqrt = 1;

        // 化简根式：找出所有的完全平方因子
        vector<llong_t> factors = prime_factors(delta);
        for (llong_t factor: factors) {
            llong_t square = factor * factor;
            while (delta % square == 0) {
                delta /= square;
                sqrt *= factor;
            }
        }
    }

    string ans;
    if (delta == 0) {
        ans = raitional_number(-b, 2 * a);
    }
    else if (delta == 1) {
        // 注意若 a < 0，则较大的那个根要取 -sqrt。
        if (a < 0)
            ans = raitional_number(-b - sqrt, 2 * a);
        else
            ans = raitional_number(-b + sqrt, 2 * a);
    }
    else {                  // iratonal number
        ans = raitional_number(-b, 2 * a);

        // 注意若 a < 0，则较大的那个根要取 -sqrt。
        if (a < 0) {
            sqrt = -sqrt;
        }

        llong_t q2_a = sqrt;
        llong_t q2_b = 2 * a;

        // 注意无理数部分正负号的处理，以及有理数为 0 时的特殊情况处理。
        if (q2_a * q2_b < 0) {
            ans += "-";
        }
        else if (ans == "0") {
            ans = "";
        }
        else {
            ans += "+";
        }

        // 后续取绝对值进行计算。
        q2_a = (q2_a > 0) ? q2_a : -q2_a;
        q2_b = (q2_b > 0) ? q2_b : -q2_b;

        if (q2_a == q2_b) {
            char buf[64];

            snprintf(buf, sizeof(buf), "%lld", delta);
            ans += "sqrt(";
            ans += buf;
            ans += ")";
        }
        else if (q2_a % q2_b == 0) {
            char buf[64];

            snprintf(buf, sizeof(buf), "%lld", q2_a / q2_b);
            ans += buf;

            snprintf(buf, sizeof(buf), "%lld", delta);
            ans += "*sqrt(";
            ans += buf;
            ans += ")";
        }
        else if (q2_b % q2_a == 0) {
            char buf[64];

            snprintf(buf, sizeof(buf), "%lld", delta);
            ans += "sqrt(";
            ans += buf;
            ans += ")/";

            snprintf(buf, sizeof(buf), "%lld", q2_b / q2_a);
            ans += buf;
        }
        else {
            llong_t c = gcd(q2_a, q2_b);
            q2_a /= c;
            q2_b /= c;

            char buf[64];

            snprintf(buf, sizeof(buf), "%lld", q2_a);
            ans += buf;
            ans += "*";

            ans += "sqrt(";
            snprintf(buf, sizeof(buf), "%lld", delta);
            ans += buf;
            ans += ")/";

            snprintf(buf, sizeof(buf), "%lld", q2_b);
            ans += buf;
        }
    }

    return ans;
}

int main()
{
    string ans;
    ans = resolve_uqe(1, 1, 1);
    assert(ans == "NO");

    ans = resolve_uqe(1, -2, 1);
    assert(ans == "1");

    ans = resolve_uqe(1, -3, 2);
    assert(ans == "2");

    ans = resolve_uqe(1, 7, 1);
    assert(ans == "-7/2+3*sqrt(5)/2");

    int T, M;
    cin >> T >> M;

    for (int i = 0; i < T; i++) {
        llong_t a, b, c;
        cin >> a >> b >> c;
        ans = resolve_uqe(a, b, c);
        cout << ans << endl;
    }

    return 0;
}

